<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>约战</title>
<link rel="stylesheet" type="text/css"	href="../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/public.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/icon.css">
<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript"	src="../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../static/js/index.js"></script>
<link rel="stylesheet" type="text/css"	href="../static/zTree/css/zTree.css">
<link rel="stylesheet" type="text/css"	href="../static/zTree/css/zTreeStyle/zTreeStyle.css">
<link rel="stylesheet" type="text/css"	href="../static/js/themes/default/easyui.css">
<script type="text/javascript"	src="../static/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript"	src="../static/zTree/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript"	src="../static/zTree/js/jquery.ztree.exedit.js"></script>
<%
		String para = request.getParameter("f_prole_id");
		int f_prole_id = 0;
		if(para != null)
			f_prole_id = Integer.valueOf(para);
		String []nonceObj=ConstantUtils.getNonceObject();
%>
<script type="text/javascript">
	var f_prra_roleId = <%=f_prole_id%>;
	var setting = {
			view: {
				selectedMulti: false
			},
			edit: {
				enable: true,
				editNameSelectAll: true,
				showRemoveBtn: false,
				showRenameBtn: false
			},
			check: {
				enable: true,
				chkStyle: "checkbox",
				chkboxType: { "Y": "ps", "N": "ps" }
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				beforeDrag: beforeDrag
			}
		};
		//禁止拖拽
		function beforeDrag(treeId, treeNodes) {
			return false;
		}
		function selectAll() {
			var zTree = $.fn.zTree.getZTreeObj("ztree");
			zTree.setting.edit.editNameSelectAll =  $("#selectAll").attr("checked");
		}
		$(document).ready(function(){
			$.ajax({
				url:"authorize_list.do",
				success:function(data){
					zNodes = JSON.parse(data);
					$.fn.zTree.init($("#ztree"), setting, zNodes);
					$("#selectAll").bind("click", selectAll);
					roleAuthorizeInit();
				}
			});
		});
		function roleAuthorizeInit() {
			$.ajax({
				url:"roleAttribute_list.do?f_prra_roleId="+f_prra_roleId,
				success:function(data) {
					data = JSON.parse(data);
					var treeObj = $.fn.zTree.getZTreeObj("ztree");
					for(var i=0;i<data.length;i++) {
						var node = treeObj.getNodeByParam("id", "a"+data[i].f_prra_attributeId, null);
						node.checked=true;
						treeObj.updateNode(node);
					}
				}
			});
		}
		function _submitFm() {
			var zTree = $.fn.zTree.getZTreeObj("ztree");
			var nodes = zTree.getCheckedNodes(true);
			var str="";
			for(var i=0;i<nodes.length;i++) {
				if(nodes[i].type=="a"&&nodes[i].pId!=null) {
					str+=nodes[i].pId+","+nodes[i].id+";"
				}
			}
			$.ajax({
				type:"POST",
				url:"roleResAtt_update.do",
				data:"f_prra_roleId="+f_prra_roleId+"&attributeStr="+str+"&stime=<%=nonceObj[0]%>&sign=<%=nonceObj[1]%>",
				success:function(data) {
					data = JSON.parse(data);
					if (data.success) {
						$.messager.progress('close');
						$.messager.alert('提示', '修改成功！', 'info', function() {
							parent.$('#dlg').dialog('close');
							parent.gotoSearch($('#easyui-treegrid'));
						});
					} else {
						$.messager.alert('提示', data.result, 'info', function() {
							$.messager.progress('close');
						});
					}
				}
			});
		}
	</script>
<title>后台 - 角色授权</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>

<body class="overfwidth">
	<div class="barnavtop">您所在的位置：角色管理 &gt; 角色授权</div>
	<div id="workspace">
		<ul id="ztree" class="ztree"></ul>
	</div>

	<div class="toolbar" style="text-align: center;">
		<a id="easyui-linkbutton" class="easyui-linkbutton"
			data-options="iconCls:'icon-ok'" href="javascript:void(0);"
			onclick="_submitFm()">保存</a> <a href="javascript:void(0);"
			data-options="iconCls:'icon-cancel'" class="easyui-linkbutton"
			onclick="javascript:parent.$('#dlg').dialog('close')">取消</a>
	</div>
</body>
</html>